<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>企业级Gradle实践指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
        }
        h1, h2, h3, h4, h5, h6 {
            font-family: 'Noto Serif SC', serif;
        }
        .code-block {
            background-color: #1e293b;
            color: #e2e8f0;
            border-radius: 0.5rem;
            overflow-x: auto;
        }
        .gradient-text {
            background: linear-gradient(90deg, #3b82f6, #8b5cf6);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <div class="relative bg-gradient-to-r from-blue-500 to-indigo-600 py-24 px-6 sm:py-32 lg:px-8">
        <div class="max-w-4xl mx-auto text-center">
            <h1 class="text-4xl md:text-6xl font-bold text-white mb-6">企业级<span class="gradient-text">Gradle</span>实践指南</h1>
            <p class="text-xl text-blue-100 max-w-3xl mx-auto">解锁现代构建工具的强大功能，实现高效、可靠的软件开发流程</p>
            <div class="mt-10 flex items-center justify-center gap-x-6">
                <a href="#content-start" class="rounded-md bg-white px-6 py-3 text-sm font-semibold text-indigo-600 shadow-sm hover:bg-indigo-50 transition-colors duration-200">
                    <i class="fas fa-book-open mr-2"></i>开始探索
                </a>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div id="content-start" class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-16">
        <!-- Introduction -->
        <div class="text-center mb-20">
            <p class="text-lg text-slate-600 max-w-3xl mx-auto leading-relaxed">
                Gradle作为现代化构建工具，已成为企业级项目构建的首选。本指南将深入探讨自定义插件开发、CI/CD集成、依赖管理等核心主题，帮助团队建立标准化、可维护的构建体系。
            </p>
        </div>

        <!-- Content Navigation -->
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8 mb-16">
            <a href="#custom-plugins" class="card-hover transition-all duration-300 bg-white rounded-xl shadow-md overflow-hidden p-6 hover:border-l-4 hover:border-indigo-500">
                <div class="flex items-center mb-4">
                    <div class="bg-indigo-100 p-3 rounded-full mr-4">
                        <i class="fas fa-puzzle-piece text-indigo-600 text-xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold text-slate-800">自定义插件开发</h3>
                </div>
                <p class="text-slate-600">掌握Gradle插件开发技术，创建符合企业标准的构建工具链</p>
            </a>
            
            <a href="#ci-cd" class="card-hover transition-all duration-300 bg-white rounded-xl shadow-md overflow-hidden p-6 hover:border-l-4 hover:border-blue-500">
                <div class="flex items-center mb-4">
                    <div class="bg-blue-100 p-3 rounded-full mr-4">
                        <i class="fas fa-sync-alt text-blue-600 text-xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold text-slate-800">CI/CD集成</h3>
                </div>
                <p class="text-slate-600">Jenkins与GitHub Actions实战配置，实现自动化构建与部署</p>
            </a>
            
            <a href="#dependency-management" class="card-hover transition-all duration-300 bg-white rounded-xl shadow-md overflow-hidden p-6 hover:border-l-4 hover:border-purple-500">
                <div class="flex items-center mb-4">
                    <div class="bg-purple-100 p-3 rounded-full mr-4">
                        <i class="fas fa-cubes text-purple-600 text-xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold text-slate-800">企业级依赖管理</h3>
                </div>
                <p class="text-slate-600">私有仓库配置与版本统一管理的最佳实践</p>
            </a>
        </div>

        <!-- Custom Plugins Section -->
        <section id="custom-plugins" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-0.5 bg-slate-200 flex-1"></div>
                <h2 class="text-3xl font-bold px-6 text-slate-800"><i class="fas fa-puzzle-piece text-indigo-600 mr-3"></i>自定义插件开发</h2>
                <div class="h-0.5 bg-slate-200 flex-1"></div>
            </div>

            <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold text-slate-800 mb-4 flex items-center">
                            <i class="fas fa-code-branch text-indigo-500 mr-2"></i>基础插件开发
                        </h3>
                        <div class="code-block p-4 rounded-lg mb-4">
                            <pre><code class="text-sm">// buildSrc/src/main/groovy/com/enterprise/VersionPlugin.groovy
class VersionPlugin implements Plugin&lt;Project&gt; {
    void apply(Project project) {
        project.extensions.create("versionConfig", VersionExtension)
        project.tasks.register('showVersion') {
            doLast {
                println "项目版本: ${project.versionConfig.release}"
            }
        }
    }
}

class VersionExtension {
    String release = "1.0.0"
    String buildNumber = "20240101"
}

// 使用插件
plugins {
    id 'com.enterprise.version'
}

versionConfig {
    release = "2.3.0"
    buildNumber = "20240501"
}</code></pre>
                        </div>
                        <p class="text-slate-600">通过实现Plugin接口创建自定义插件，使用扩展对象配置插件参数。</p>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold text-slate-800 mb-4 flex items-center">
                            <i class="fas fa-upload text-indigo-500 mr-2"></i>插件发布
                        </h3>
                        <div class="code-block p-4 rounded-lg mb-4">
                            <pre><code class="text-sm">// 插件项目的build.gradle
plugins {
    id 'java-gradle-plugin'
    id 'maven-publish'
}

gradlePlugin {
    plugins {
        enterprisePlugin {
            id = 'com.enterprise.quality'
            implementationClass = 'com.enterprise.QualityPlugin'
        }
    }
}

publishing {
    repositories {
        maven {
            url = "http://nexus.internal/repository/gradle-plugins/"
            credentials {
                username = "deploy-user"
                password = "s3cr3t"
            }
        }
    }
}</code></pre>
                        </div>
                        <p class="text-slate-600">使用maven-publish插件发布自定义插件到私有仓库，实现团队共享。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- CI/CD Integration Section -->
        <section id="ci-cd" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-0.5 bg-slate-200 flex-1"></div>
                <h2 class="text-3xl font-bold px-6 text-slate-800"><i class="fas fa-sync-alt text-blue-600 mr-3"></i>Gradle与CI/CD集成</h2>
                <div class="h-0.5 bg-slate-200 flex-1"></div>
            </div>

            <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold text-slate-800 mb-4 flex items-center">
                            <i class="fab fa-jenkins text-blue-500 mr-2"></i>Jenkins Pipeline示例
                        </h3>
                        <div class="code-block p-4 rounded-lg mb-4">
                            <pre><code class="text-sm">// Jenkinsfile
pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                sh './gradlew clean build'
            }
        }
        stage('Test') {
            steps {
                sh './gradlew test'
                junit 'build/test-results/**/*.xml'
            }
        }
        stage('SonarQube') {
            steps {
                withSonarQubeEnv('sonar-server') {
                    sh './gradlew sonarqube'
                }
            }
        }
    }
}</code></pre>
                        </div>
                        <p class="text-slate-600">Jenkins Pipeline定义构建、测试和代码质量检查阶段，实现自动化流程。</p>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold text-slate-800 mb-4 flex items-center">
                            <i class="fab fa-github text-blue-500 mr-2"></i>GitHub Actions配置
                        </h3>
                        <div class="code-block p-4 rounded-lg mb-4">
                            <pre><code class="text-sm"># .github/workflows/build.yml
name: Java CI

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Set up JDK 17
      uses: actions/setup-java@v3
      with:
        java-version: '17'
        distribution: 'temurin'
    - name: Build with Gradle
      run: ./gradlew build
    - name: Upload Artifacts
      uses: actions/upload-artifact@v3
      with:
        name: build-output
        path: build/libs/*.jar</code></pre>
                        </div>
                        <p class="text-slate-600">GitHub Actions配置实现跨平台构建，自动上传构建产物。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Enterprise Dependency Management -->
        <section id="dependency-management" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-0.5 bg-slate-200 flex-1"></div>
                <h2 class="text-3xl font-bold px-6 text-slate-800"><i class="fas fa-cubes text-purple-600 mr-3"></i>企业级依赖管理</h2>
                <div class="h-0.5 bg-slate-200 flex-1"></div>
            </div>

            <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold text-slate-800 mb-4 flex items-center">
                            <i class="fas fa-server text-purple-500 mr-2"></i>私有仓库配置
                        </h3>
                        <div class="code-block p-4 rounded-lg mb-4">
                            <pre><code class="text-sm">// settings.gradle
dependencyResolutionManagement {
    repositories {
        maven {
            url "http://nexus.internal/repository/maven-public/"
            allowInsecureProtocol = true
            credentials {
                username = "read-user"
                password = "p@ssw0rd"
            }
        }
    }
}

// 版本统一管理
// gradle/libs.versions.toml
[versions]
spring-boot = "3.1.5"

[libraries]
spring-boot-starter = { module = "org.springframework.boot:spring-boot-starter", version.ref = "spring-boot" }</code></pre>
                        </div>
                        <p class="text-slate-600">配置私有Maven仓库并启用依赖版本集中管理，确保构建一致性。</p>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold text-slate-800 mb-4 flex items-center">
                            <i class="fas fa-microchip text-purple-500 mr-2"></i>微服务配置示例
                        </h3>
                        <div class="code-block p-4 rounded-lg mb-4">
                            <pre><code class="text-sm">// service-account/build.gradle
plugins {
    id 'org.springframework.boot'
    id 'io.spring.dependency-management'
}

dependencies {
    implementation project(':common:security')
    implementation libs.spring.boot.starter.web
    implementation 'com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery:2022.0.0.0'
    
    testImplementation libs.spring.boot.starter.test
}

bootJar {
    archiveFileName = "account-service-${version}.jar"
    launchScript()
}</code></pre>
                        </div>
                        <p class="text-slate-600">微服务项目典型配置，展示模块依赖和打包定制。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Advanced Topics -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-0.5 bg-slate-200 flex-1"></div>
                <h2 class="text-3xl font-bold px-6 text-slate-800"><i class="fas fa-cogs text-amber-600 mr-3"></i>高级定制与扩展</h2>
                <div class="h-0.5 bg-slate-200 flex-1"></div>
            </div>

            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="p-6">
                    <h3 class="text-xl font-semibold text-slate-800 mb-4 flex items-center">
                        <i class="fas fa-play text-amber-500 mr-2"></i>初始化脚本示例
                    </h3>
                    <div class="code-block p-4 rounded-lg mb-4">
                        <pre><code class="text-sm">// gradle/init.d/corporate.gradle
allprojects {
    repositories {
        maven { url "http://nexus.internal/repository/maven-public/" }
    }
    
    tasks.withType(Test) {
        useJUnitPlatform()
        testLogging {
            events "passed", "skipped", "failed"
        }
    }
}</code></pre>
                    </div>
                    <p class="text-slate-600">通过初始化脚本实现企业级全局配置，统一所有项目的构建行为。</p>
                </div>
            </div>
        </section>

        <!-- Case Study -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="h-0.5 bg-slate-200 flex-1"></div>
                <h2 class="text-3xl font-bold px-6 text-slate-800"><i class="fas fa-lightbulb text-emerald-600 mr-3"></i>案例分析</h2>
                <div class="h-0.5 bg-slate-200 flex-1"></div>
            </div>

            <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold text-slate-800 mb-4 flex items-center">
                            <i class="fab fa-java text-emerald-500 mr-2"></i>Spring Boot项目配置分析
                        </h3>
                        <div class="code-block p-4 rounded-lg mb-4">
                            <pre><code class="text-sm">// 典型Spring Boot配置
plugins {
    id 'java'
    id 'org.springframework.boot' version '3.1.5'
    id 'io.spring.dependency-management' version '1.1.3'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:2022.0.4"
    }
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
}</code></pre>
                        </div>
                        <p class="text-slate-600">Spring Boot项目典型配置，展示依赖管理和插件应用。</p>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold text-slate-800 mb-4 flex items-center">
                            <i class="fas fa-exchange-alt text-emerald-500 mr-2"></i>迁移策略实施步骤
                        </h3>
                        <div class="mermaid bg-slate-50 p-4 rounded-lg">
                            graph TD
                                A[评估阶段] -->|使用工具生成脚本| B(增量迁移)
                                B --> C[优化阶段]
                                C --> D[验证阶段]
                                A -->|分析插件对应关系| B
                                B -->|先迁移非核心模块| C
                                C -->|引入构建缓存| D
                                D -->|对比构建产物| E[完成迁移]
                        </div>
                        <p class="text-slate-600 mt-4">四阶段迁移策略确保平滑过渡，最小化对开发流程的影响。</p>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            mermaid.initialize({
                startOnLoad: true,
                theme: 'default',
                flowchart: {
                    useMaxWidth: true,
                    htmlLabels: true,
                    curve: 'basis'
                }
            });
        });
    </script>
</body>
</html>